<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('产权信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金全称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金全称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('基金简称')" prop="fundAbbreviation">
        <el-input
          v-model="queryParams.fundAbbreviation"
          :placeholder="$t('基金简称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('基金类型')" prop="fundType">
        <el-select v-model="queryParams.fundType" :placeholder="$t('基金类型')" clearable>
          <el-option
            v-for="dict in fundTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('成立时间')" prop="establishTime">
        <DatePicker v-model="establishTimes" type="daterange" />
      </el-form-item>
      <el-form-item :label="$t('基金管理公司')" prop="fundManagementCompanyName">
        <el-input
          v-model="queryParams.fundManagementCompanyName"
          :placeholder="$t('基金管理公司')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:property:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="propertyFundList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金全称')" align="center" prop="fundName" width="200">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/property/propertyFundHome',query:{id:scope.row.id,companyId : scope.row.id}}"
            class="link_a"
          >{{ scope.row.fundName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金简称')" align="center" prop="fundAbbreviation" width="170" />
      <el-table-column :label="$t('基金类型')" align="center" prop="fundType" :formatter="fundTypeFormat" width="120" />
      <el-table-column :label="$t('成立日期')" align="center" prop="establishTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.establishTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('续存期限')" align="center" prop="duration" width="120" />
      <el-table-column :label="$t('注册地')" align="center" prop="detailsRegistered" width="120" />
      <el-table-column :label="$t('基金管理公司')" align="center" prop="fundManagementCompanyName" width="170" />
      <el-table-column fixed="right" :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>

      <el-table-column :label="$t('操作')" align="center" fixed="right" class-name="small-padding fixed-width" width="230">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.fundId"
            size="small"
            type="text"
            target="_blank"
            icon="el-icon-view"
            @click="goFundLink(scope.row)"
          >{{ $t('基金信息') }}</el-button>
          <el-button
            v-if="scope.row.actStatus === 'W'"
            v-hasPermi="['fund:property:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('变更') }}</el-button>
          <el-button
            v-if="scope.row.actStatus !== 'D' && scope.row.actStatus !== 'W'"
            v-hasPermi="['fund:property:edit']"
            size="small"
            type="text"
            icon="el-icon-video-play"
            @click="updateHandle(scope.row)"
          >{{ $t("启动流程") }}
          </el-button>
          <!--带审批状态下可以终止流程-->
          <el-button
            v-if="scope.row.actStatus === 'D'"
            v-hasPermi="['fund:property:edit']"
            size="small"
            type="text"
            icon="el-icon-video-pause"
            @click="stopProcess(scope.row)"
          >{{ $t("终止流程") }}</el-button>
          <el-button
            v-if="scope.row.actStatus !== 'D' && scope.row.actStatus !== 'W'"
            v-hasPermi="['fund:property:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
          <!--          <ListBtn :bus-data="scope.row" has-permi="fund:property" />-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产权信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <propertyFundForm ref="propertyFundForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listPropertyFund, delPropertyFund, exportPropertyFund } from '@/api/fund/property/propertyFund'
import propertyFundForm from './propertyFundForm.vue'
export default {
    components: {
        propertyFundForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 产权信息表格数据
          propertyFundList: [],
          // 弹出层标题
          title: '产权信息',
          // 是否显示弹出层
          formOpen: false,
        // 一级登记类型字典
        levelOneRegistrationTypeOptions: [],

        // 基金类型字典
        fundTypeOptions: [],

        establishTimes: [],
          // 查询参数
          queryParams: {
              fundName: undefined,
              fundAbbreviation: undefined,
              fundType: undefined,
              establishTime: undefined,
              fundManagementCompanyName: undefined,
              startDate: undefined,
              endDate: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
        // 终止流程按钮是否展示
        stopBtn: function() {
          if (this.busData.actStatus === 'D') {
            return true
          } else {
            return false
          }
        }
      }
  },
  created() {
      this.getList()
      this.getDicts('fund_registration_type').then(response => {
          this.levelOneRegistrationTypeOptions = response.data
      })
      this.getDicts('property_fund_type').then(response => {
          this.fundTypeOptions = response.data
      })
  },
  methods: {
    /** 查询产权信息列表 */
    getList() {
        this.loading = true
        if (this.establishTimes !== null && this.establishTimes.length > 1) {
          this.queryParams.startDate = this.establishTimes[0]
          this.queryParams.endDate = this.establishTimes[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listPropertyFund(this.queryParams).then(response => {
            this.propertyFundList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },
    // 一级登记类型字典翻译
    levelOneRegistrationTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.levelOneRegistrationTypeOptions, row.levelOneRegistrationType)
    },
    // 基金类型字典翻译
    fundTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.fundTypeOptions, row.fundType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            fundId: undefined,
            levelOneRegistrationType: undefined,
            levelTwoRegistrationType: undefined,
            fundName: undefined,
            fundAbbreviation: undefined,
            fundType: undefined,
            establishTime: undefined,
            duration: undefined,
            detailsRegistered: undefined,
            fundManagementCompany: undefined,
            managementAmountRatio: undefined,
            groupDischargePeopleNumber: undefined,
            chairman: undefined,
            actuallyManaged: undefined,
            investmentCommitteePeopleNumber: undefined,
            fundContact: undefined,
            fundContactNumber: undefined,
            totalFundSize: undefined,
            mainInvestment: undefined,
            totalInvestedCapital: undefined,
            existingProjectsNumber: undefined,
            receiveDividends: undefined,
            fundValuation: undefined,
            fundValuationTime: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.establishTimes = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.propertyFundForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.propertyFundForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delPropertyFund(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportPropertyFund(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    },
    goFundLink(row) {
      const routeData = this.$router.resolve({
        fromPath: this.$route.fullPath,
        path: '/fund/fundBasehome',
        query: { id: row.fundId }
      })
      // 指定跳转地址
      window.open(routeData.href, '_blank')
    }
  }
}
</script>
